-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: resolve React warnings and accessibility issues #1763
Conversation
- Move chatProfile selection logic into useEffect - Add null checks for config object - Fix React warning about setState during render"
- Update Markdown component to handle heading elements properly - Fix HTML validation warnings"
- Fix DOM nesting validation warnings - Maintain existing styling and layout"
- Add key to React.Fragment in message map function - Fix React warning about missing keys in list
- Replace Button component with styled DropdownMenuTrigger - Fix DOM nesting warning for button elements
- Move ThreadOptions outside of SidebarMenuButton - Fix DOM nesting warnings
- Add proper optional chaining for config access - Move setChatProfile call to useEffect - Fix TypeScript warnings about potential undefined values
- Make text comparison more resilient by using trim() - Focus on functional correctness rather than exact formatting - Maintain existing test coverage while improving reliability"
- Remove unused import 'size' from ChatProfiles
- Add eslint-disable-next-line for Card and Table imports - Fix lint errors while preserving markdown table functionality - Ensure ESLint correctly recognizes component usage in table renderer
Head branch was pushed to by a user without write access
frontend/src/components/chat/Messages/Message/Content/index.tsx
Outdated
Show resolved
Hide resolved
- Add early return to prevent unnecessary renders and resource waste - Handle case when no profile is selected - Handle case when selected profile becomes invalid - Remove redundant config.chatProfiles existence checks
Hi @hexart , there is another issue, which is in #chat-input, I type something then remove all, then the |
I suggest handling the empty message validation in a separate PR. This current one focuses on DOM/rendering fixes, while input validation is a different concern. I'll create a new PR to address the send button and empty message issues. |
No worry, I submitted a PR to fix the issue. |
I am not sure what this section does const containsBlockElement = useMemo(
() =>
React.Children.toArray(props.children).some((child) => {
if (!React.isValidElement(child)) return false;
if (
/^h[1-6]$/.test(child.type as string) ||
child.type === 'p'
) {
return true;
}
if (
child.props?.['data-type'] === 'Alert' ||
(typeof child.type === 'function' &&
child.type.name === 'AlertComponent')
) {
return true;
}
if (React.isValidElement(child) && child.props?.children) {
return React.Children.toArray(child.props.children).some(
(grandChild) =>
React.isValidElement(grandChild) &&
(grandChild.type === 'div' ||
(typeof grandChild.type === 'string' &&
grandChild.type.toLowerCase() === 'div'))
);
}
return false;
}),
[props.children] Other changes look good to me but it would be nice to have some comments explaining why we need to know if the paragraph contains certain blocks. |
@willydouhard As I understand, that is for checking when to use |
Can't we always use a div then instead of adding logic? |
@willydouhard the intention seems to keep the original |
While using div everywhere might seem simpler, using semantic HTML tags like
I'll add comments to explain this rationale in the code. |
I don't think SEO is related in the chatbot context. Can you explain why would div affect screen reader and document structure clarity? I do think this logic affect the maintenance effort of the project. Not sure if the benefit worth adding this complex check. |
You make great points about the context of our application. You're right that in a chatbot UI, we might be over-engineering by adding complex checks for semantic HTML. Would you be open to this simpler approach? Something like: p(props) {
const commonClassNames = 'leading-7 [&:not(:first-child)]:mt-4 whitespace-pre-wrap break-words';
return <div {...omit(props, ['node'])} className={commonClassNames} role="paragraph" />;
} |
That totally makes sense. changing "role" to paragraph and avoid this complex logic LGTM. |
Thanks for fixing this. We kind of need this change before we can release with chainlit v2. |
I guess we can also use role="article" if needed as mentioned here https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/article_role |
Yes, you're right, already fix it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
This PR fixes multiple React warnings, accessibility issues and DOM nesting problems across several components:
<h2>
and<p>
tags in Markdown componentWarning before fix
Screenshots
Fixes
Fixed Accessibility Issues in
LeftSidebar/Search.tsx
:Fixed React Component State Issues in
header/ChatProfiles.tsx
:Optimized Profile Selection Logic in
header/ChatProfiles.tsx
:Fixed DOM Nesting Issues:
LeftSidebar/ThreadOptions.tsx
Markdown.tsx
componentFixed
e2e/command/spec.cy.ts
Test Cases:Testing Done
Types of changes